package org.hismig.migration.result;

import java.util.Date;

import org.hismig.utils.DateTool;

/**
 * @declare: //TODO <br />
 *           This class created by Vansion.Hopihit on 2012-8-17 <br />
 *           <a href="mailto:vansionhopihit@gmail.com">Contact Me</a>
 * @version 1.0
 * @author Vansion.Hopihit
 * 
 */
public class RunResultInfo {

	private Date startDate;
	private long startTime;

	private int runCount = 0;
	private int errorCount = 0;

	public RunResultInfo() {
		startDate = new Date();
		startTime = System.currentTimeMillis();
	}

	public int getRunCount() {
		return runCount;
	}

	public void addRunCount() {
		runCount++;
	}

	public int getErrorCount() {
		return errorCount;
	}

	public void addErrorCount() {
		errorCount++;
	}

	public Date getStartDate() {
		return startDate;
	}

	public String formate() {

		StringBuffer sb = new StringBuffer();
		sb.append("<html>");
		sb.append(String.format("<strong>开始运行 : </strong>%s<p>",
				DateTool.getNormalDateTime(startDate)));
		sb.append(String.format("<strong>调度次数 : </strong>%s<p>", runCount));
		sb.append(String.format("<strong>成功次数 : </strong>%s<p>", runCount
				- errorCount));

		sb.append(String.format("<strong>失败次数 : </strong>%s<p>", errorCount));
		sb.append(String.format("<strong>运行时长 : </strong>%s<p>", DateTool
				.getFormateRanTime((System.currentTimeMillis() - startTime))));

		sb.append("</html>");

		return sb.toString();
	}

	@Override
	public String toString() {
		return String.format("开始运行:%s - (调度%s次 失败:%s)",
				new Object[]{DateTool.getNormalDateTime(startDate), runCount,
						errorCount});
	}

}
